package com.atguigu.controller;

import com.atguigu.bean.User;
import com.atguigu.service.UserService;
import com.atguigu.service.impl.UserServiceImpl;
import com.atguigu.utils.ViewBaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * projectName: javaweb
 *
 * @author: 赵伟风
 * time: 2022/7/4 14:20 周一
 * description: 用于用户数据查询展示，最终userList.html
 */
@WebServlet("/user/show")
public class UserShowController extends ViewBaseServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 设置编码格式
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //2. 获取请求参数
        //3. 调用业务逻辑
        UserService userService = new UserServiceImpl();
        List<User> userList = userService.show();
        //4. 响应前端数据
        //数据存储到共享域
        req.setAttribute("userList",userList);
        //跳转到userList.html
        processTemplate("userList",req,resp);
    }

}
